package com.cw.part3.controller;

import com.cw.part3.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 使用传统的方法。来实现库存的购买和减少功能
     */
    @RequestMapping("/buyOrder")
    public HashMap buyOrder(Integer productId) {
        String result = orderService.publishOrder(productId + "");
        HashMap map = new HashMap();
        map.put("result", result);

        return map;

    }

    @RequestMapping("/publishOrderBySynchronized")
    public HashMap publishOrderBySynchronized(Integer productId) {
        String result = orderService.publishOrderBySynchronized(productId + "");
        HashMap map = new HashMap();
        map.put("result", result);

        return map;

    }

    @RequestMapping("/publishOrderByRedis")
    public HashMap publishOrderByRedis(Integer productId) {
        String result = orderService.publishOrderByRedis(productId + "");
        HashMap map = new HashMap();
        map.put("result", result);

        return map;

    }
}
